﻿using System;

namespace MessagePack.Formatters
{
	// Token: 0x02000029 RID: 41
	public class StaticNullableFormatter<T> : IMessagePackFormatter<T?> where T : struct
	{
		// Token: 0x06000094 RID: 148 RVA: 0x000038B8 File Offset: 0x00001CB8
		public StaticNullableFormatter(IMessagePackFormatter<T> underlyingFormatter)
		{
			this.underlyingFormatter = underlyingFormatter;
		}

		// Token: 0x06000095 RID: 149 RVA: 0x000038C7 File Offset: 0x00001CC7
		public int Serialize(ref byte[] bytes, int offset, T? value, IFormatterResolver formatterResolver)
		{
			if (value == null)
			{
				return MessagePackBinary.WriteNil(ref bytes, offset);
			}
			return this.underlyingFormatter.Serialize(ref bytes, offset, value.Value, formatterResolver);
		}

		// Token: 0x06000096 RID: 150 RVA: 0x000038F8 File Offset: 0x00001CF8
		public T? Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
		{
			if (MessagePackBinary.IsNil(bytes, offset))
			{
				readSize = 1;
				return null;
			}
			return new T?(this.underlyingFormatter.Deserialize(bytes, offset, formatterResolver, out readSize));
		}

		// Token: 0x0400001D RID: 29
		private readonly IMessagePackFormatter<T> underlyingFormatter;
	}
}
